package org.iku;

import java.util.Calendar;
import java.util.Map;
import java.util.Map.Entry;

import org.heydr.Crawler;
import org.heydr.annotation.HandleInfo;
import org.heydr.common.Config;
import org.heydr.concurrent.CrawlerEngine;
import org.heydr.concurrent.CrawlerEngine.CrawlerGenerator;
import org.heydr.data.ResourceEngine;
import org.heydr.handler.impl.SubHandler;
import org.heydr.impl.SimpleCrawler;
import org.iku.index.ItemIndexBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Ikuzo {
	private static Logger logger = LoggerFactory.getLogger(Ikuzo.class);

	public static void main(String[] args) {
		logger.info("i ku zo ……");
		ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
		long time = context.getStartupDate();
		/* 建立索引 */
		ItemIndexBuilder builder = (ItemIndexBuilder)context.getBean("itemIndexBuilder");
		builder.build();
		
		/* 資源爬蟲 */
//		ResourceEngine resourceEngine = (ResourceEngine)context.getBean("itemResourceEngine");
//		
//		Map<String,SubHandler> map = context.getBeansOfType(SubHandler.class);
//		Config config = (Config)context.getBean("crawlConfig");
//		CrawlerEngine.go(config,resourceEngine,map,new CrawlerGenerator() {
//			@Override
//			public Crawler generateCrawler() {
//				return new SimpleCrawler();
//			}
//		});
		/* 資源爬蟲 */
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time);
		logger.info("ikuzo service start at :"+calendar.getTime());
	}
	
}
